using System;
using System.IO;
using System.Text;

namespace MSHelpLib
{
	/// <summary>
	/// Summary description for BaseStructure.
	/// </summary>
	public class BaseStructure
	{
        /// <summary>
        /// Normallizes the name of the file.
        /// </summary>
        /// <param name="FileName">Name of the file.</param>
        /// <returns></returns>
		public string NormallizeFileName(string FileName)
		{
			string NewName=FileName.ToLower();
			NewName=NewName.Replace(@"\","/");
			if (!NewName.StartsWith("/"))
				NewName="/"+NewName;
			return NewName;
		}

        /// <summary>
        /// Checks the sig.
        /// </summary>
        /// <param name="Sig1">The sig1.</param>
        /// <param name="Sig2">The sig2.</param>
        /// <returns></returns>
		public bool CheckSig(string Sig1, char[] Sig2)
		{
			int i=0;
			foreach(char ch in Sig1.ToCharArray())
			{
				if (ch!=Sig2[i])
					return false;
				i++;
			}
			return true;
		}

		// skip a compressed dword 
        /// <summary>
        /// Skip_cwords the specified st.
        /// </summary>
        /// <param name="st">The st.</param>
		public void skip_cword(BinaryReader st)
		{		
			byte b=0;
			while ((b=st.ReadByte())>= 0x80);			
		}

		// parse a compressed dword 
        /// <summary>
        /// _chm_parse_cwords the specified st.
        /// </summary>
        /// <param name="st">The st.</param>
        /// <returns></returns>
		public UInt64 _chm_parse_cword(BinaryReader st)
		{
			UInt64 accum = 0;
			byte temp=0;			
			while ((temp=st.ReadByte()) >= 0x80)
			{
				accum <<= 7;
				accum += (ulong)(temp & 0x7f);
			}

			return (accum << 7) + temp;
		}

		// parse a utf-8 string into an ASCII char buffer 
        /// <summary>
        /// _chm_parse_s the UT f8.
        /// </summary>
        /// <param name="st">The st.</param>
        /// <param name="count">The count.</param>
        /// <param name="path">The path.</param>
        /// <returns></returns>
		public int _chm_parse_UTF8(BinaryReader st, UInt64 count, ref string path)
		{
			UTF8Encoding utf8=new UTF8Encoding();
			path=utf8.GetString(st.ReadBytes((int)count),0,(int)count);							
			return 1;
		}
	}
}
